#include "SQLDropTriggerStatement.h"

#include "../SQLName.h"
#include "../../../DbType.h"
#include "SQLDDLStatement.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../SQLObject.h"
#include "../SQLExpr.h"

SQLDropTriggerStatement::SQLDropTriggerStatement()
{
}

SQLDropTriggerStatement::SQLDropTriggerStatement(DbType_ptr   dbType) : SQLStatementImpl(dbType)
{
}

SQLName_ptr SQLDropTriggerStatement::getName()
{
  return name;
}

void SQLDropTriggerStatement::setName(SQLName_ptr name)
{
  this->name = name;
}

void SQLDropTriggerStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLDropTriggerStatement)))
  {
    acceptChild(visitor, name);
  }
  visitor->endVisit(SharedObject(SQLDropTriggerStatement));
}

SQLObject_list_ptr SQLDropTriggerStatement::getChildren()
{
  SQLObject_list_ptr  children = std::make_shared<std::list<SQLObject_ptr>>();
  if (name != NULL)
  {
    children->push_back(std::dynamic_pointer_cast<SQLObject>(name));
  }
  return children;
}

BOOL_ptr SQLDropTriggerStatement::isIfExists()
{
  return ifExists;
}

void SQLDropTriggerStatement::setIfExists(BOOL_ptr ifExists)
{
  this->ifExists = ifExists;
}

BOOL_ptr SQLDropTriggerStatement::replace(SQLExpr_ptr expr, SQLExpr_ptr target)
{
  if (name == expr)
  {
    setName(std::dynamic_pointer_cast<SQLName>(target));
    return BOOL::TRUE;
  }

  return BOOL::FALSE;
}

SQLDDLStatement::DDLObjectType SQLDropTriggerStatement::getDDLObjectType()
{
  return SQLDDLStatement::DDLObjectType::TRIGGER;
}
